import scrapy
from scrapy_01.items import Scrapy01Item
from scrapy.http import Request,FormRequest

'''
爬取哔哩哔哩目录，如动画，音乐等等用来测试
'''
class BilibiliSpider(scrapy.Spider):
    name = 'bilibili'
    # allowed_domains = ['www.bilibili.com']
    start_urls = ['http://www.bilibili.com/']

    def parse(self, response):
        self.items = Scrapy01Item()
        lists = response.xpath('//*[@id="primaryChannelMenu"]/span/div/a/span')
        yield Request("http://c.biancheng.net/view/2027.html",callback=self.next1)
        for list in lists:
            name = list.xpath('./text()').extract()
            num = list.xpath('./em/text()').extract()
            self.items["name"] = name[0]
            self.items["num"] = num[0]
            self.items['info'] = self.info
            # print(self.info)
            yield self.items

    def next1(self,response):
        self.info = response.xpath('//*[@id="arc-body"]/text()[15]').extract()[0]
        self.items['info'] = self.info


